<template>
	<view class="">
		<web-view  :webview-styles="webviewStyles" :src="weburl"></web-view>
		<uni-popup ref="popup">
			<view class="" style="width: 100%;height: 800rpx;background-color: #000000;">
				
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import akicryptojs from '@/uni_modules/aki-cryptojs/js_sdk/aki-cryptojs'
	export default {
		data() {
			return {
				weburl:"",
				webviewStyles: {
					progress: {
						color: '#00aa7f',
						paddingTop:"500rpx"
					}
				},
				code:"",
				time:null,
				userInfo:""
			};
		},
		onLoad(data) {
			console.log("跳转参数",data)
			if(data.weburl){
				this.weburl = data.weburl
				if(data.token){
					this.weburl =this.weburl+"&token="+data.token
					console.log(this.weburl)
				}
			}
			if(data.code){
				this.code = data.code
				this.getRewards1();
			}
			// let data1 = {custom:JSON.stringify({title:"看小说得奖励",intregral:17,levelValue:20})}
			// this.alert(data1);
		},
		onShow() {
			this.userInfo = uni.getStorageSync(this.$util.USER_INFO)
		},
		methods:{
			getH5Award(data,status){
				let that = this
				let name = 'getAward'
				if(this.$environment === 'dev'){
					name = 'ceshi-getAward'
				}
				uniCloud.callFunction({
					name: name,
					data: data,
					success(res) {
						console.log("请求完成", res)
						let result = res.result
						console.log(result.isValid)
						setTimeout(()=>{
							that.getStatus = false
						},2000)
						if(result.isValid){
							status.status = 1
							that.$util.showInfoToast("领取奖励成功")
						}else {
							that.$util.showInfoToast(result.message)
						}
					},
					fail() {},
					complete() {}
				})
			},
			//领取奖励
			getRewards(status,type){
				let transId = new Date().getTime() + "";
				let time = null
				let sign = akicryptojs.EncryptHmacSHA256(transId, this.$util.APPID)
				if(this.getStatus){
					return
				}
				this.getStatus = true
				let data = {
					extra: 'APP',
					adpid: 1027948601,
					transId: transId,
					rcode:this.userInfo.rcode,
					time:time,
					sign: sign,
					type:type,
					provider: status.code,
					platform: uni.getSystemInfoSync().platform,
					toKen: uni.getStorageSync(this.$util.USER_TOKEN_KEY)
				}
				console.log("领取激励奖励")
				this.getH5Award(data,status);
			},
			getRewards1(){
				let time=0
				this.time = setInterval(()=>{
					time++
					console.log("观看了",time)
					if(time>=30){ 
						clearInterval(this.time);
						this.time = null;
						let type = 0
						if(this.code =="h5") {
							type = 2
							console.log(this.$api.prePage().h5Status)
							let h5Status = this.$api.prePage().h5Status
							h5Status.status = 1
							this.getRewards(h5Status,type)
						}else if(this.code =="news") {
							type = 3
							let newsStatus = this.$api.prePage().newsStatus
							newsStatus.status = 1
							this.getRewards(newsStatus,type)
						}
					}
				},1000)
				
			},
		},
		beforeDestroy() {
			if(this.time){
				clearInterval(this.time);
				this.time = null;
			}
		}
	}
</script>

<style lang="scss">
	page{
	}
</style>
